import Vue from 'vue'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
import store from '@/store'

Vue.use(VueRouter)
Vue.use(Vuex)

const routes = [
  {path: '/login',name: '登录',component: () => import('../views/admin/Login.vue')},
  {path: '/register',name: '注册', component: () => import('../views/admin/Register.vue')},
  {
    path: '/',
    component: () => import('../views/Manage.vue'),
    redirect: "/user",
    children: [
      { path: 'user', name: '用户管理', component: () => import('../views/Manage/User.vue')},
      { path: 'notice', name: '公告管理', component: () => import('../views/Manage/Notice.vue')},
      { path: 'post', name: '讨论管理', component: () => import('../views/Manage/Post.vue')},
      { path: 'comment', name: '回复管理', component: () => import('../views/Manage/Comment.vue')},
      { path: 'suggest', name: '意见反馈管理', component: () => import('../views/Manage/Suggest.vue')},
      { path: 'apply', name: '事件申请管理', component: () => import('../views/Manage/Apply.vue')},
      { path: 'person', name: '个人信息', component: () => import('../views/admin/Person.vue')},
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login'||from.path === '/login') {
//     next();
//   } else {
 
//     if (!this.$store.state.userInfo) {
//       next('/login');
//     } else {
//       next();
//     }
//   }
// });

export default router
